1. Field of the Invention
The present invention generally relates to a method, system and program product for implementing single threaded optimizations in a potentially multi-threaded environment. Specifically, the present invention allows single threaded optimizations to be legally implemented in appropriate program code.
2. Related Art
As programming languages advance, computer programs can generally be categorized into groups that are capable of generating a single thread, and those that are capable of generating multiple threads. Based on this categorization, certain optimizations can be performed. For example, if a program is capable of only generating a single thread, the program can be desynchronized, its globals can be optimized, etc. Such single-threaded optimizations should not be implemented with programs having multi-thread capability at the risk of causing incorrect execution. To this extent, the possibility that multiple threads could be created by a program constrains analyses and restricts the code transformations that can be performed.
Most programming languages have a fixed set of primitives under which a new thread can be created. Unfortunately, no existing system provides the capability to examine a program for the potential to generate multiple threads without performing whole program analysis (i.e., seeing every piece of code that might be run), and then make optimizations based on the determination. This is an especially difficult task for dynamic loading environments where it is not possible to determine in advance if multiple threads cannot be generated. Specifically, in a dynamic compilation environment, examination results could change as the program continues to run/execute. To this extent, existing systems also fail to provide a system whereby an examination result and subsequent optimization that later proves to be erroneous can be reversed.
In view of the foregoing, there exists a need for a method, system and program product for implementing single threaded optimizations in a potentially multi-threaded environment. Specifically, a need exists for a system that is capable of examining (dynamically or statically) program code for multi-thread potential. A further need exists for the system to implement single threaded optimizations if the examination reveals that multi-thread potential is not present. Still yet, a need exists for the system to be able to take corrective steps in the event a program is later revealed to have multi-thread potential. This need is especially apparent in an environment with dynamic loading where it is not possible to determine in advance if multiple threads cannot be generated.